<?php
class Studies_Model extends ORM {
	
	protected $table_name = 'studies';
	protected $primary_key = 'studies_id';
	protected $col_sort_order = 'studies_sort_order';
	protected $col_status = 'studies_status';
	protected $sorting = array('studies_id' => 'desc');
	
	public function get()
	{
		$this->db->from($this->table_name);
		$this->db->select('*');
		$this->db->orderby($this->col_sort_order,'desc');
		$this->db->orderby($this->primary_key,'desc');
		$query = $this->db->get();
		return $query->result_array(false);
		
	}
	
	public function get_with_active($language)
	{
		$this->db->select('*');
		$this->db->from($this->table_name);
		$this->db->join('studies_content', 'studies_content.studies_id', 'studies.studies_id');
		$this->db->where('studies_content.languages_id',$language);
		$this->db->where($this->col_status,'1');
		$this->db->orderby('studies.'.$this->col_sort_order,'desc');
		$this->db->orderby('studies.'.$this->primary_key,'desc');
		$query = $this->db->get();
		return $query->result_array(false);
		
	}
	public function count_row()
	{
		$this->db->select('COUNT('.$this->primary_key.') AS max');
		$this->db->from($this->table_name);
        $this->db->orderby($this->col_sort_order,'asc');
		$query = $this->db->get();
		return $query->result_array(false);
	}
	public function get_oder()
	{
		$this->db->from($this->table_name);
		$this->db->select($this->primary_key);
		$this->db->orderby($this->col_sort_order,'asc');
		$query = $this->db->get();
		return $query->result_array(false);
		
	}

}
?>